from django.db import models

# Create your models here.
from django.utils import timezone


# 消息表
class MessageInfo(models.Model):
    type_choices = (
        ('0', '参加活动消息'),
        ('1', '活动审核结果消息'),
        ('2', '退出活动消息'),
    )

    status_choices = (
        ('0', '未读消息'),
        ('1', '已读消息'),
        ('2', '已删消息'),
    )

    message_status = models.CharField(verbose_name='消息状态', choices=status_choices, max_length=1, default='0')
    message_type = models.CharField(verbose_name='消息种类', choices=type_choices, max_length=1, default='0')
    sender = models.ManyToManyField('user.UserInfo', verbose_name='发送者', related_name='send_message_id', blank=True,
                                    db_index=True)
    receiver = models.ManyToManyField('user.UserInfo', verbose_name='接收者', related_name='receiver_message_id',
                                      blank=True, db_index=True)
    message_content = models.CharField(verbose_name='消息内容', max_length=150, default='')
    message_title = models.CharField(verbose_name='消息标题', max_length=20, default='')
    message_create_time = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    join_activity_id = models.IntegerField(verbose_name='活动id', default=0)

    class Meta:
        db_table = 'messageinfo'
        verbose_name = "消息表"
        verbose_name_plural = verbose_name

    def __str__(self):
        """将模型类以字符串的方式输出"""
        return self.message_title


# 文件表
class FileInfo(models.Model):
    message = models.ForeignKey(MessageInfo, verbose_name='消息体', related_name='file_list_id', on_delete=models.SET_NULL,
                                null=True, db_index=True)
    file_accessory = models.FileField(verbose_name='附件', upload_to='messageFile', default='')

    class Meta:
        db_table = 'fileinfo'
        verbose_name = "文件表"
        verbose_name_plural = verbose_name
